// var Api = "http://songyujianiu.qicp.vip/";
var Api = "http://localhost:9000";
var app = new Vue({
	el: "#app",
	data: function() {
		return {
			loginName: "",
			password: "",
			message: "ss",
			uid: "666",
			phonenumber:"",
			email:'',
			eadit:''
			
		};
	},
	created: function() {
		this.finduserbyid();
		/* new Vue({  
		  methods: {
		  function(){
		  // 查询用户model
		  const par = new URLSearchParams();
		  par.append("id",that.uid)
		  
		let that = this;
		axios({
		  method: "post",
		  url: Api + "/users/finduserbyid",
		  params: par,
		}).then(function (res) {
		  	  console.log(res);
		  	  if (res.data.code == "101") {
		  	    //layer.msg("注册成功", { time: 1000 });
		  	  
		  	  } else {
		  	   
		  	    //layer.msg(res.data.message, { time: 1000 });
		  	  }
		  	});
			}
			},
			}); */

	},
	methods: {
		// 查询用户model
		finduserbyid: function() {
			this.uid = window.localStorage.getItem("uid");
			/* alert(this.uid); */
			let that = this;
			const par = new URLSearchParams();
			par.append("id", that.uid)
			axios({
				method: "post",
				url: Api + "/users/finduserbyid",
				params: par,
			}).then(function(res) {
				/* console.log(res); */
				if (res.data.code == "101") {
					that.phonenumber = res.data. data.phonenumber;
					that.email = res.data.data.email;
					that.loginName = res.data.data.loginName;
					//alert(that.loginName);
					that.password = res.data.data.password;
					time: 1000
				} else {

					layer.msg(res.data.message, {
						time: 1000
					});
				}
			});
		},
		// 保存
		updateuser: function() {
			let that = this;
			// alert(11)
			console.log("app");

			if (that.loginName.split(" ").join("").length === 0) {
				// alert("用户名不能为空")
				layer.msg("用户名不能为空", {
					time: 1000
				});
				return;
			}

			if (that.password.split(" ").join("").length === 0) {
				// alert("密码不能为空")
				layer.msg("密码不能为空", {
					time: 1000
				});
				return;
			}
			this.uid = window.localStorage.getItem("uid");
			const par = new URLSearchParams();
			par.append("loginName", that.loginName);
			par.append("password", that.password);
			par.append("email", that.email);
			par.append("phonenumber", that.phonenumber);
			par.append("uid",that.uid);
			axios({
				method: "post",
				url: Api + "/users/updateuser",
				params: par,
			}).then(function(res) {
				console.log(res);
				if (res.data.code == "101") {
					// alert("注册成功");
					layer.msg("修改成功", {
						time: 1000
					});
					window.location.href = "index.html";
				} else {
					layer.msg(res.data.message, {
						time: 1000
					});
				}
			});
		},
		//  弹出框的全选
		handleSelectionChange(val) {
			console.log(val);
			var arr = [];
			let that = this;
			for (const item in val) {
				arr.push(val[item].userId);
			}
			that.userId = arr;
		},
		//  分页
		handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
		},
	},
});
